package com.dmyang.user.service;

import com.dmyang.common.DataSource;
import com.dmyang.common.DataSourceType;
import com.dmyang.user.dao.TeacherMapper;
import com.dmyang.user.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by brss on 2017/7/20.
 */
@Service("userServiceImpl")
public class UserServiceImpl implements UserService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    @Transactional
    @DataSource(DataSourceType.MASTER)  //走主库
    public int createTeacher(Teacher teacher) {


        teacherMapper.insert(teacher);
        return 0;
    }

    @DataSource(DataSourceType.SLAVE)
    @Override
    public int query() {
        Teacher teacher = teacherMapper.selectByPrimaryKey(1);
        System.out.println("hello");
        return 0;
    }
}
